﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace JaikuClient
{
    static class Program
    {
        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern ushort GlobalAddAtom(string lpString);

        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern ushort GlobalFindAtom(string lpString);

        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern ushort GlobalDeleteAtom(ushort atom);

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            string atomStr = Application.ProductName + Application.ProductVersion;
            ushort Atom = GlobalFindAtom(atomStr);
            if (Atom > 0)
            {
            MessageBox.Show("One one instance of Jaiku Client can run at one time!");
            }
            else
            {
            Atom = GlobalAddAtom(atomStr);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainForm());
            GlobalDeleteAtom(Atom);
            }

        }
    }
}
